﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace zvsWF
{
    public partial class FormEditZVS : Form
    {
        public FormEditZVS()
        {
            InitializeComponent();
        }
        public string sdate;
        public string edate;
        public string sent_id;
        public string semps_id;
        public string subject;
        public int curemps_indx;
        private void buttonCurrentSDate_Click(object sender, EventArgs e)
        {
            dateTimePickerSDate.Value = DateTime.Now;
            textBoxTimeSDate.Text = DateTime.Now.ToString("HH:mm");
        }

        private void buttonCurrentEDate_Click(object sender, EventArgs e)
        {
            checkEditIsEDate.Checked = true;
            dateTimePickerEDate.Value = DateTime.Now;
            textBoxTimeEDate.Text = DateTime.Now.ToString("HH:mm");
        }

 
        private void checkEditIsEDate_CheckedChanged(object sender, EventArgs e)
        {
            dateTimePickerEDate.Visible = checkEditIsEDate.Checked;
            textBoxTimeEDate.Visible = checkEditIsEDate.Checked;
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            sdate = String.Format("#{0} {1}#", dateTimePickerSDate.Value.ToString("yyyy-MM-dd"), textBoxTimeSDate.Text);
            if (checkEditIsEDate.Checked)
                edate = String.Format("#{0} {1}#", dateTimePickerEDate.Value.ToString("yyyy-MM-dd"), textBoxTimeEDate.Text);
            else
                edate = "null";
            PrjTmpl prjtmpl = (PrjTmpl)comboBoxEnt.SelectedValue;
            sent_id = prjtmpl.RowID;
            prjtmpl = (PrjTmpl)comboBoxEmps.SelectedValue;
            semps_id = prjtmpl.RowID;
            subject = textBoxTask.Text;
           
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void FormEditZVS_Shown(object sender, EventArgs e)
        {
            comboBoxEnt.DataSource = PrjProperty.listEnt;
            comboBoxEnt.DisplayMember = "Value";
            comboBoxEmps.DataSource = PrjProperty.listEmps;
            comboBoxEmps.DisplayMember = "Value";
            comboBoxEmps.SelectedIndex = curemps_indx;

            if (sent_id.ToString() != "")
            {
                int sid = 0;
                int i = -1;
                foreach (PrjTmpl pt in comboBoxEnt.Items)
                {
                    i++;
                    if (sent_id == pt.RowID)
                        sid = i;
                }
                comboBoxEnt.SelectedIndex = sid;
            }
            if (semps_id.ToString() != "")
            {
                int sid = 0;
                int i = -1;
                foreach (PrjTmpl pt in comboBoxEmps.Items)
                {
                    i++;
                    if (semps_id == pt.RowID)
                        sid = i;
                }
                comboBoxEmps.SelectedIndex = sid;
            }
        }
    }
}
